﻿using GrapeCity.Forguncy.CellTypes;
using GrapeCity.Forguncy.Commands;
using GrapeCity.Forguncy.Plugin;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Windows;
using Vant.Properties;
using Vant.WpfControls;
using Vant.WpfControls.DrawingObject;

namespace Vant.CellTypes
{
    public class NoticeBarDesigner : CellTypeDesigner<NoticeBar>, ISupportStyleInitialize, ISupportPropertyInitialize
    {
        public override FrameworkElement GetDrawingControl(ICellInfo cellInfo, IDrawingHelper drawingHelper)
        {
            var cellStyleViewModel = StyleHelper.CreateStyleViewModel(cellInfo, drawingHelper);
            return new NoticeBarDrawingObject(this.CellType, cellStyleViewModel, cellInfo, drawingHelper);
        }
        public Dictionary<StylePropertyName, object> GetDefaultStyleInfos(ICellInfo cellInfo)
        {
            return new Dictionary<StylePropertyName, object>() { { StylePropertyName.Background, "#fffbe8" } };
        }

        public void InitDefaultPropertyValues(IBuilderContext context)
        {
            if (context.Cell != null && string.IsNullOrEmpty(context.Cell.Value?.ToString()))
            {
                context.Cell.Value = Resources.NoticeBar_CellValue;
            }
            this.CellType.leftIcon = new ImageValue()
            {
                BuiltIn = true,
                Color = "#ed6a0c",
                Name = "Mobile/411_notice_1.svg",
                UseCellTypeForeColor = true
            };
        }
    }

    [Designer("Vant.CellTypes.NoticeBarDesigner, Vant")]
    [Icon("pack://application:,,,/Vant;component/Resources/Images/NoticeBar.png")]
    [OrderWeight((int)Utils.OrderWeight.NoticeBar)]
    public class NoticeBar : VantCellTypeBase, ISupportDefaultValue
    {
        [SRDisplayName(nameof(Resources.EditCommand))]
        [CustomCommandObject]
        public object ClickCommand { get; set; }

        [SRDisplayName(nameof(Resources.NoticeBar_DefaultValue))]
        [SRDescription(nameof(Resources.NoticeBar_DefaultValue_Description))]
        [FormulaProperty(AcceptsReturn = true)]
        public object DefaultValue { get; set; }

        [SRDisplayName(nameof(Resources.NoticeBar_Mode))]
        [SRComboProperty(ValueList = "none|closeable|link", DisplayList = nameof(Resources.NoticeBar_Mode_ComboProperty_DisplayList))]
        public string mode { get; set; } = "none";

        [SRDisplayName(nameof(Resources.LeftIcon))]
        [IconProperty(SupportUseCellColor = true)]
        public ImageValue leftIcon { get; set; }

        [SRDisplayName(nameof(Resources.NoticeBar_ScrollMode))]
        [SRRadioGroupProperty(ValueList = "none|horizontal|vertical", DisplayList = nameof(Resources.NoticeBar_ScrollMode_RadioGroupProperty_DisplayList))]
        public string scrollMode { get; set; } = "horizontal";

        [SRDisplayName(nameof(Resources.NoticeBar_Autoplay))]
        [IntProperty(Min = 1)]
        [DefaultValue(3000)]
        public int autoplay { get; set; } = 3000;

        [SRDisplayName(nameof(Resources.NoticeBar_Duration))]
        [IntProperty(Min = 1)]
        [DefaultValue(500)]
        public int duration { get; set; } = 500;

        [SRDisplayName(nameof(Resources.NoticeBar_Delay))]
        [IntProperty(Min = 0)]
        [DefaultValue(1)]
        public int delay { get; set; } = 1;

        [SRDisplayName(nameof(Resources.NoticeBar_Speed))]
        [IntProperty(Min = 1)]
        [DefaultValue(60)]
        public int speed { get; set; } = 60;

        public bool NeedFormatDefaultValue => false;

        public override bool GetDesignerPropertyVisible(string propertyName)
        {
            if (propertyName == nameof(delay) ||
                propertyName == nameof(speed))
            {
                return scrollMode == "horizontal";
            }
            if (propertyName == nameof(autoplay) ||
                propertyName == nameof(duration))
            {
                return scrollMode == "vertical";
            }
            return base.GetDesignerPropertyVisible(propertyName);
        }

        public override string ToString()
        {
            return Resources.NoticeBar;
        }
    }
}
